<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>新增兑换券</title>
		<link href="../../static/css/font-awesome.css" rel="stylesheet" />

		<style type="text/css">
			.nav>li:hover .dropdown-menu {
				display: block;
			}
		</style>

		<link href="../../static/css/bootstrap.min.css" rel="stylesheet" />
		<link href="../../static/css/font-awesome.css" rel="stylesheet" />
		<!-- bootstrap-table 表格插件样式 -->
		<link href="../../static/ajax/libs/bootstrap-table/bootstrap-table.min.css" rel="stylesheet" />
		<link href="../../static/ajax/libs/bootstrap-treetable/bootstrap-treetable.css" rel="stylesheet" />
		<link href="../../static/css/animate.css" rel="stylesheet" />
		<link href="../../static/css/style.css" rel="stylesheet" />
		<link href="../../static/css/checkbox.css" rel="stylesheet" />
		<link href="../../static/ajax/libs/select/select2.css" rel="stylesheet" />
		<link href="../../static/galaxy/css/ry-ui.css" rel="stylesheet" />
		<style type="text/css">
			.btn {
				padding-top: 3px;
				padding-bottom: 3px;
			}
			
			.form-horizontal {
				padding-top: 20px;
			}
		</style>
	</head>

	<body class="gray-bg">
		<div id="converty">
			<div class="wrapper wrapper-content animated fadeInRight ibox-content row" style="margin: 10px 35px;    padding-bottom: 0px;">
				<div style="border-left: 8px solid rgba(65, 186, 207, 1);font-weight: 700;">
					&nbsp;&nbsp;&nbsp;兑换券
					<div style="float: right;    font-size: 12px;">
						<!--<button type="button" class="btn btn-primary">启用</button>
						<button type="button" class="btn btn-default active">编辑</button>
						<button type="button" class="btn btn-default active">删除</button>-->
					</div>
				</div>
				<form class="form-horizontal m" id="form-info-add">

					<div class="row">
						<div class="col-sm-6">
							<div class="form-group">
								<label class="col-sm-3 control-label">兑换券名称：</label>
								<div class="col-sm-8">
									<input id="devName" name="devName" class="form-control" type="text" placeholder="请输入">
								</div>
							</div>

							<div class="form-group">
								<div style="width: 50%;float: left;">
									<label class="col-sm-6 control-label">原价：</label>
									<div class="col-sm-6 ">
										<input id="price" name="voltage1" class="form-control" type="number" min="0.01">
									</div>
								</div>
								<div style="width: 50%;float: left;">
									<label class="col-sm-4  control-label">现价：</label>
									<div class="col-sm-6">
										<input id="initprice" name="voltage2" class="form-control"  type="number" min="0.01">
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">有效期：</label>
								<div class="col-sm-8 form-inline">
									<input id="timeFrom" name="voltage1" class="form-control" type="date"> -
									<input id="timeTo" name="voltage2" class="form-control" type="date">
								</div>
							</div>
							<!--<div class="form-group">
								<label class="col-sm-3 control-label">使用周期：</label>
								<div class="col-sm-8 form-inline">
									<input id="current1" name="current1" class="form-control" type="date"> - 
									<input id="current2" name="current2" class="form-control" type="date">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">使用时间：</label>
								<div class="col-sm-8 form-inline">
									<input id="cableTemperature1" name="cableTemperature1" class="form-control" type="date"> - 
									<input id="cableTemperature2" name="cableTemperature2" class="form-control" type="date">
								</div>
							</div>-->
							<div class="form-group">
								<label class="col-sm-3 control-label">使用规则：</label>
								<div class="col-sm-8 form-inline">
									<textarea id="remark" class="form-control" style="width: 100%;"></textarea>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">数量：</label>
								<div class="col-sm-8">
									<input id="num" name="devName" class="form-control" type="number" min="1" placeholder="请输入张">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">绑定结算模板：</label>
								<div class="col-sm-8 form-inline">
									<select id="settpro" class="form-control input-sm" style="width: 100%;padding-top: 5px;">
										<option value="">结算模板</option>
										<option value="">结算模板</option>
										<option value="">结算模板</option>
										<option value="">结算模板</option>
									</select>
								</div>
							</div>
						</div>
						<!--<div class="col-sm-6">
					    	<div class="form-group">	
								<label class="col-sm-3 control-label">套餐内容：</label>
								<div class="row form-group">
								    <div class="col-sm-6">
								      <input type="text" class="form-control" placeholder="请输入内容">
								    </div>
								    <div class="col-sm-2">
								      <input type="text" class="form-control" placeholder="价格">
								    </div>
								</div>
								<label class="col-sm-3 control-label"></label>
								<div class="row form-group">
								    <div class="col-sm-6">
								      <input type="text" class="form-control" placeholder="请输入内容">
								    </div>
								    <div class="col-sm-2">
								      <input type="text" class="form-control" placeholder="价格">
								    </div>
								</div>
								<label class="col-sm-3 control-label"></label>
								<div class="row form-group">
								    <div class="col-sm-6">
								      <input type="text" class="form-control" placeholder="请输入内容">
								    </div>
								    <div class="col-sm-2">
								      <input type="text" class="form-control" placeholder="价格">
								    </div>
								</div>
								<label class="col-sm-3 control-label"></label>
								<div class="row form-group">
								    <div class="col-sm-6">
								      <input type="text" class="form-control" placeholder="请输入内容">
								    </div>
								    <div class="col-sm-2">
								      <input type="text" class="form-control" placeholder="价格">
								    </div>
								</div>
								<label class="col-sm-3 control-label"></label>
								<div class="row form-group">
								    <div class="col-sm-6">
								      <input type="text" class="form-control" placeholder="请输入内容">
								    </div>
								    <div class="col-sm-2">
								      <input type="text" class="form-control" placeholder="价格">
								    </div>
								</div>
								<label class="col-sm-3 control-label"></label>
								<div class="row form-group">
								    <div class="col-sm-6">
								      <input type="text" class="form-control" placeholder="请输入内容">
								    </div>
								    <div class="col-sm-2">
								      <input type="text" class="form-control" placeholder="价格">
								    </div>
								</div>
								<label class="col-sm-3 control-label"></label>
								<div class="row form-group">
								    <div class="col-sm-6">
								      <input type="text" class="form-control" placeholder="请输入内容">
								    </div>
								    <div class="col-sm-2">
								      <input type="text" class="form-control" placeholder="价格">
								    </div>
								</div>
							</div>
					    </div>-->
					</div>
				</form>
			</div>
		</div>
		<div style="text-align: center;" align="center">
			<!--<button type="button" class="btn btn-primary" onclick="addConverTy();">新增兑换券</button>-->
			<button id="item_submit_save" type="button" class="btn btn-primary active">确定</button>
			<button onclick="location.href='convertibility.html'" type="button" class="btn btn-default">返回</button>
		</div>
		<script src="../../static/js/jquery.min.js"></script>
		<script src="../../static/js/bootstrap.min.js"></script>
		<script src="../../static/js/echarts.common.min.js"></script>

		<!-- bootstrap-table 表格插件 -->
		<script src="../../static/ajax/libs/bootstrap-table/bootstrap-table.min.js"></script>
		<script src="../../static/ajax/libs/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
		<script src="../../static/ajax/libs/bootstrap-table/extensions/mobile/bootstrap-table-mobile.min.js"></script>
		<script src="../../static/ajax/libs/bootstrap-table/extensions/toolbar/bootstrap-table-toolbar.min.js"></script>
		<!-- jquery-validate 表单验证插件 -->
		<script src="../../static/ajax/libs/validate/jquery.validate.min.js"></script>
		<script src="../../static/ajax/libs/validate/messages_zh.min.js"></script>
		<script src="../../static/ajax/libs/validate/jquery.validate.extend.js"></script>
		<!-- jquery-validate 表单树插件 -->
		<script src="../../static/ajax/libs/bootstrap-treetable/bootstrap-treetable.js"></script>
		<!-- jquery-export 表格导出插件 -->
		<script src="../../static/ajax/libs/bootstrap-table/extensions/export/bootstrap-table-export.js"></script>
		<script src="../../static/ajax/libs/bootstrap-table/extensions/export/tableExport.js"></script>
		<!-- 遮罩层 -->
		<script src="../../static/ajax/libs/blockUI/jquery.blockUI.js"></script>
		<script src="../../static/ajax/libs/layer/layer.min.js"></script>
		<script src="../../static/ajax/libs/layui/layui.js"></script>
		<script src="../../static/galaxy/js/common.js?v=2.3.0"></script>
		<script src="../../static/galaxy/js/ry-ui.js?v=2.3.0"></script>
		<script type="text/javascript" src="../../static/js/app/app.js"></script>
		<script type="text/javascript" src="../../static/js/lib/MD5.js"></script>
		<script type="text/javascript" src="../../static/js/app/net.js"></script>
		<script type="text/javascript">
			jQuery(document).ready(function() {

				var re = GetRequest();
				var id = parseInt(re['id']);
				var shop = parseInt(re['shop']);
				if(!id || id == 0) {
					loadsett(0);
					clinc();
				} else {
					initcoupon();
				}

			});

			function addConverTy() {
				var convertys = $('#converty');
				var html = '';
				html += '<div class="wrapper wrapper-content animated fadeInRight ibox-content row" style="margin: 10px 35px;    padding-bottom: 0px;">\n' +
					'    <div style="border-left: 8px solid rgba(65, 186, 207, 1);font-weight: 700;">\n' +
					'    &nbsp;&nbsp;&nbsp;兑换券\n' +
					'    <div style="float: right;    font-size: 12px;">  \n' +
					'    <button type="button" class="btn btn-primary">启用</button>\n' +
					'    <button type="button" class="btn btn-default active">编辑</button>\n' +
					'    <button type="button" class="btn btn-default active">删除</button>\n' +
					'    </div>\n' +
					'    </div>\n' +
					'        <form class="form-horizontal m" id="form-info-add">\n' +
					'        \n' +
					'         <div class="row">\n' +
					'<div class="col-sm-6">\n' +
					'      <div class="form-group">\n' +
					'<label class="col-sm-3 control-label">兑换券名称：</label>\n' +
					'<div class="col-sm-8">\n' +
					'<input id="devName" name="devName" class="form-control" type="text" placeholder="请输入">\n' +
					'</div>\n' +
					'</div>\n' +
					'\n' +
					'<div class="form-group">\n' +
					'<label class="col-sm-3 control-label">原价：</label>\n' +
					'<div class="col-sm-8 form-inline">\n' +
					'<input id="voltage1" name="voltage1" class="form-control" type="text" style="width: 40%;">\n' +
					'<label class="control-label" style="    padding-left: 30px;padding-top: 0px;">现价：</label> \n' +
					'<input id="voltage2" name="voltage2" class="form-control" type="text" style="width: 40%;">\n' +
					'</div>\n' +
					'</div>\n' +
					'<div class="form-group">\n' +
					'<label class="col-sm-3 control-label">有效期：</label>\n' +
					'<div class="col-sm-8 form-inline">\n' +
					'<input id="voltage1" name="voltage1" class="form-control" type="text"> - \n' +
					'<input id="voltage2" name="voltage2" class="form-control" type="text">\n' +
					'</div>\n' +
					'</div>\n' +
					'<div class="form-group">\n' +
					'<label class="col-sm-3 control-label">使用周期：</label>\n' +
					'<div class="col-sm-8 form-inline">\n' +
					'<input id="current1" name="current1" class="form-control" type="text"> - <input id="current2" name="current2" class="form-control" type="text">\n' +
					'</div>\n' +
					'</div>\n' +
					'<div class="form-group">\n' +
					'<label class="col-sm-3 control-label">使用时间：</label>\n' +
					'<div class="col-sm-8 form-inline">\n' +
					'<input id="cableTemperature1" name="cableTemperature1" class="form-control" type="text"> - <input id="cableTemperature2" name="cableTemperature2" class="form-control" type="text">\n' +
					'</div>\n' +
					'</div>\n' +
					'<div class="form-group">\n' +
					'<label class="col-sm-3 control-label">使用规则：</label>\n' +
					'<div class="col-sm-8 form-inline">\n' +
					'<textarea class="form-control" style="width: 100%;"></textarea>\n' +
					'</div>\n' +
					'</div>\n' +
					'<div class="form-group">\n' +
					'<label class="col-sm-3 control-label">绑定结算模板：</label>\n' +
					'<div class="col-sm-8 form-inline">\n' +
					'    <select class="form-control input-sm" style="width: 100%;padding-top: 5px;">\n' +
					'      <option value="">结算模板</option>\n' +
					'      <option value="">结算模板</option>\n' +
					'      <option value="">结算模板</option>\n' +
					'      <option value="">结算模板</option>\n' +
					'    </select>\n' +
					'</div>\n' +
					'</div>\n' +
					'     </div> \n' +
					//		        '    <div class="col-sm-6">\n' +
					//		        '    <div class="form-group">\n' +
					//		        '<label class="col-sm-3 control-label">套餐内容：</label>\n' +
					//		        '<div class="row form-group">\n' +
					//		        '    <div class="col-sm-6">\n' +
					//		        '      <input type="text" class="form-control" placeholder="请输入内容">\n' +
					//		        '    </div>\n' +
					//		        '    <div class="col-sm-2">\n' +
					//		        '      <input type="text" class="form-control" placeholder="价格">\n' +
					//		        '    </div>\n' +
					//		        '</div>\n' +
					//		        '<label class="col-sm-3 control-label"></label>\n' +
					//		        '<div class="row form-group">\n' +
					//		        '    <div class="col-sm-6">\n' +
					//		        '      <input type="text" class="form-control" placeholder="请输入内容">\n' +
					//		        '    </div>\n' +
					//		        '    <div class="col-sm-2">\n' +
					//		        '      <input type="text" class="form-control" placeholder="价格">\n' +
					//		        '    </div>\n' +
					//		        '</div>\n' +
					//		        '<label class="col-sm-3 control-label"></label>\n' +
					//		        '<div class="row form-group">\n' +
					//		        '    <div class="col-sm-6">\n' +
					//		        '      <input type="text" class="form-control" placeholder="请输入内容">\n' +
					//		        '    </div>\n' +
					//		        '    <div class="col-sm-2">\n' +
					//		        '      <input type="text" class="form-control" placeholder="价格">\n' +
					//		        '    </div>\n' +
					//		        '</div>\n' +
					//		        '<label class="col-sm-3 control-label"></label>\n' +
					//		        '<div class="row form-group">\n' +
					//		        '    <div class="col-sm-6">\n' +
					//		        '      <input type="text" class="form-control" placeholder="请输入内容">\n' +
					//		        '    </div>\n' +
					//		        '    <div class="col-sm-2">\n' +
					//		        '      <input type="text" class="form-control" placeholder="价格">\n' +
					//		        '    </div>\n' +
					//		        '</div>\n' +
					//		        '<label class="col-sm-3 control-label"></label>\n' +
					//		        '<div class="row form-group">\n' +
					//		        '    <div class="col-sm-6">\n' +
					//		        '      <input type="text" class="form-control" placeholder="请输入内容">\n' +
					//		        '    </div>\n' +
					//		        '    <div class="col-sm-2">\n' +
					//		        '      <input type="text" class="form-control" placeholder="价格">\n' +
					//		        '    </div>\n' +
					//		        '</div>\n' +
					//		        '<label class="col-sm-3 control-label"></label>\n' +
					//		        '<div class="row form-group">\n' +
					//		        '    <div class="col-sm-6">\n' +
					//		        '      <input type="text" class="form-control" placeholder="请输入内容">\n' +
					//		        '    </div>\n' +
					//		        '    <div class="col-sm-2">\n' +
					//		        '      <input type="text" class="form-control" placeholder="价格">\n' +
					//		        '    </div>\n' +
					//		        '</div>\n' +
					//		        '<label class="col-sm-3 control-label"></label>\n' +
					//		        '<div class="row form-group">\n' +
					//		        '    <div class="col-sm-6">\n' +
					//		        '      <input type="text" class="form-control" placeholder="请输入内容">\n' +
					//		        '    </div>\n' +
					//		        '    <div class="col-sm-2">\n' +
					//		        '      <input type="text" class="form-control" placeholder="价格">\n' +
					//		        '    </div>\n' +
					//		        '</div>\n' +
					//		        '</div>\n' +
					//		        '    </div>\n' +
					'  </div>\n' +
					'</form>\n' +
					'</div>';
				convertys.append(html);
			}

			function loadsett(setid) {

				var re = GetRequest();
				var shop = re['shop'];
				//查询参数准备
				var info = {
					page: 1,
					rows: 100,
					type: "wxselect",
					shop: parseInt(shop)
				};

				//接口调用
				var str = '<option value=0>请选择</option>';
				doPost("shop/addSettletempitem", info, function(data) {
					//加载数据列表
					if(data.success) {
						var data = data.data;
						var r = data.rows;
						var type = "";
						for(var i = 0; i < r.length; i++) {
							syslog(r[i]);
							if(setid == r[i].id){
								str += '<option value=' + r[i].id + ' selected>' + r[i].name + '</option>';
							}else{
								str += '<option value=' + r[i].id + '>' + r[i].name + '</option>';
							}
							
						}
						$('#settpro').html("");
						$('#settpro').append(str);

					}

				});
			};

			//编辑事件
			function initcoupon() {
				
				var re = GetRequest();
				var id = parseInt(re['id']);
				//			e.preventDefault();
				//			var btn1 = document.getElementById('check_code_btn');
				//			btn1.style.display = 'none';
				//			document.getElementById('code').readOnly = true;
				//			$('#examinesCode').slideDown('slow');
				//新增提交数据
				var info = {
					id: id
				};
				doPost("shop/selectManageCoupons", info, function(data) {
					if(data.success) {
						var data = data.data;
						var r = data.rows;
						//					$('[name="id"]').val(r[0].id);
						//					$('[name="shopname"]').val(r[0].shopname);
						//					$('[name="shopid"]').val(r[0].shop);
						//					$('[name="code"]').val(r[0].shopcode);
						$("#timeFrom").val(r[0].timefrom);
						$("#timeTo").val(r[0].timeto);
						$("#num").val(r[0].num);
						//					$('[name="percount"]').val(r[0].percount);
						$("#devName").val(r[0].couponname);
						//					$('[name="usedNum"]').val(r[0].usednum);
						$("#remainNum").val(r[0].remainnum);
						$("#price").val(r[0].couponprice);
						$("#initprice").val(r[0].price);
						//					$('[name="daycount"]').val(r[0].daycount);
						//					$('input[name="couponstype"][value="' + r[0].description + '"]').prop("checked", "checked");
						$("#remark").val(r[0].remark);
						$("#settpro").val(r[0].settmentId);
						//					document.getElementById('settpro').value = r[0].name

						loadsett(r[0].settmentId);
					} else if(data.code == 400) {
						alert(data.desc);
					}
				});

			};

			$('#item_submit_save').click(function(e) {
				var re = GetRequest();
				var id = parseInt(re['id']);
				var shop = parseInt(re['shop']);

				//新增提交数据
				var info = {
					timeFrom: $('#timeFrom').val(),
					timeTo: $('#timeTo').val(),
					name: $('#devName').val(),
					price: $('#price').val(),
					initprice: $('#initprice').val(),
					num: parseInt($('#num').val()),
					//				percount: parseInt($('#percount').val()),
					//				daycount: parseInt($('#daycount').val()),
					settmentId: parseInt($("#settpro").val()),
					id:id,
					shop: parseInt(shop),
					//				description: parseInt($('input[name="couponstype"]:checked').val()),
					remark: $('#remark').val(),
					type: "兑换券"
				};
				if(!id || id == 0) {
					doPost("shop/addShopcoupon", info, function(data) {

						if(data.success) {

							alert('提交成功');
							window.location.href = "/aityWeb/view/convertibility/convertibility.html?shop="+shop;
						} else if(data.code == 400) {
							alert(data.desc);
						}
					});
				} else {
					doPost("shop/updateManageCoupons", info, function(data) {
						if(data.success) {
							alert('提交成功');
							window.location.href = "/aityWeb/view/convertibility/convertibility.html?shop="+shop;
						} else if(data.code == 400) {
							alert(data.desc);
						}
					});
				}
			});

			function clinc() {

				//	var sets = getSettings();
				//	if(sets.isShopUser){
				//		document.getElementById('shopcode').style.display = 'none';
				//		//获取页面参数
				//		var r = GetRequest();
				//		var shopid = parseInt(r['shopid']);
				//		$('[name="shopid"]').val(shopid);
				//	}
				$('[name="timeFrom"]').val("");
				$('[name="timeTo"]').val("");
				$('[name="num"]').val("");
				$('[name="name"]').val("");
				$('[name="price"]').val("");
				$('[name="initprice"]').val("");
				$('[name="remark"]').val("");

			};
			//取消
			$('#item_close').click(function(e) {
				$('#add_item_modal').modal('hide');
			});

			function GetRequest() {
				var url = location.search; //获取url中"?"符后的字串
				var theRequest = new Object();
				if(url.indexOf("?") != -1) {
					var str = url.substr(1);
					strs = str.split("&");
					for(var i = 0; i < strs.length; i++) {
						var name = strs[i].split("=")[0];
						var value = strs[i].split("=")[1];
						//theRequest[name]=unescape(value);
						theRequest[name] = decodeURI(value);
					}
				}
				return theRequest;
			};
		</script>
	</body>

</html>